function [ theta12Step3,lambda] = theta12Step3(namesTheta12,theta1Step1,AVarTheta1Step1,theta2Step2,AVarTheta2Step2)

% Computing lambda and theta12Step3
numTheta12        = size(namesTheta12,1);
lambda            = zeros(numTheta12,numTheta12);
for i=1:numTheta12
    posTheta1    = find(strcmp(AVarTheta1Step1.names,namesTheta12(i)));
    posTheta2    = find(strcmp(AVarTheta2Step2.names,namesTheta12(i)));
    lambda(i,i)  = AVarTheta2Step2.VarRobustTheta2(posTheta2,posTheta2)/(AVarTheta1Step1.VarRobustTheta1(posTheta1,posTheta1)+AVarTheta2Step2.VarRobustTheta2(posTheta2,posTheta2));
    theta12Step3.(namesTheta12{i}) = lambda(i,i)*getfield(theta1Step1,namesTheta12{i}) + ...
        (1-lambda(i,i))*getfield(theta2Step2,namesTheta12{i});
end

end

